﻿<%@ Page Language="C#" AutoEventWireup="true" Codebehind="ManagePageContent.aspx.cs"
    Inherits="AffiliateClick.Admin.ManagePageContent" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Manage Page Content</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager1" />
        <div>
            <table>
                <tr>
                    <td valign="top">
                        <asp:GridView ID="gv_PageContent" runat="server" DataSourceID="SqlDS_PageContent"
                            AutoGenerateColumns="false" DataKeyNames="ID" SelectedIndex="0" Width="500px"
                            OnRowDeleted="gv_PageContent_RowDeleted">
                            <EmptyDataTemplate>
                                No Data Found.
                                <asp:Button ID="btnInsert" runat="server" Text="Insert One" OnClick="Detail_Insert" />
                            </EmptyDataTemplate>
                            <Columns>
                                <asp:CommandField ShowSelectButton="true" ShowDeleteButton="true" ItemStyle-Width="50px" />
                                <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" ItemStyle-Width="50px" />
                                <asp:BoundField DataField="ContentKey" HeaderText="Content Key" SortExpression="ContentKey"
                                    ItemStyle-Width="50px" />
                                <asp:TemplateField HeaderText="Language" SortExpression="LanguageKey">
                                    <ItemTemplate>
                                    <asp:Literal ID="literal_chinese" runat="server" Text="<%$ Resources:GlobalResource,Chinese%>" Visible='<%#DataBinder.Eval(Container.DataItem,"LanguageKey").Equals("zh-CN")%>'></asp:Literal>
                                    <asp:Literal ID="literal_english" runat="server" Text="<%$ Resources:GlobalResource,English%>" Visible='<%#DataBinder.Eval(Container.DataItem,"LanguageKey").Equals("en-US")%>'></asp:Literal>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" ItemStyle-Width="150px" />
                            </Columns>
                        </asp:GridView>
                        <p>
                            <asp:DetailsView AutoGenerateRows="False" DataKeyNames="ID" DataSourceID="Details"
                                HeaderText="Page Content Details" ID="dv_PageContent" runat="server" Width="275px"
                                OnItemInserted="dv_PageContent_ItemInserted" OnItemUpdated="dv_PageContent_ItemUpdated">
                                <Fields>
                                    <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" InsertVisible="false"
                                        SortExpression="ID" />
                                    <asp:TemplateField HeaderText="Content Key" SortExpression="ContentKey">
                                        <EditItemTemplate>
                                            <asp:DropDownList runat="server" ID="ddl_ContentKey" SelectedValue='<%# DataBinder.Eval(Container.DataItem,"ContentKey")%>'>
                                                <asp:ListItem Text="<%$ Resources:GlobalResource,MainPage%>" Value="MainPage" />
                                                <asp:ListItem Text="<%$ Resources:GlobalResource,News%>" Value="News" />
                                            </asp:DropDownList>
                                        </EditItemTemplate>
                                        <InsertItemTemplate>
                                            <asp:DropDownList runat="server" ID="ddl_ContentKey">
                                                <asp:ListItem Text="<%$ Resources:GlobalResource,MainPage%>" Value="MainPage" />
                                                <asp:ListItem Text="<%$ Resources:GlobalResource,News%>" Value="News" />
                                            </asp:DropDownList>
                                        </InsertItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("ContentKey") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Language" SortExpression="LanguageKey">
                                        <EditItemTemplate>
                                            <asp:DropDownList runat="server" ID="ddl_Language" SelectedValue='<%# DataBinder.Eval(Container.DataItem,"LanguageKey").Equals("zh-CN")?"zh-CN" : "en-US" %>'>
                                                <asp:ListItem Text="<%$ Resources:GlobalResource,Chinese%>" Value="zh-CN" />
                                                <asp:ListItem Text="<%$ Resources:GlobalResource,English%>" Value="en-US" />
                                            </asp:DropDownList>
                                        </EditItemTemplate>
                                        <InsertItemTemplate>
                                            <asp:DropDownList runat="server" ID="ddl_Language" SelectedValue='<%# Profile.GetPropertyValue("PreferredCulture").ToString() %>'>
                                                <asp:ListItem Text="<%$ Resources:GlobalResource,Chinese%>" Value="zh-CN" />
                                                <asp:ListItem Text="<%$ Resources:GlobalResource,English%>" Value="en-US" />
                                            </asp:DropDownList>
                                        </InsertItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("LanguageKey") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Title" SortExpression="Title">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="txtBoxText" runat="server" Text='<%# Bind("Title") %>' Columns="50"></asp:TextBox>
                                            <br />
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator_Text" runat="server" ControlToValidate="txtBoxText"
                                                Display="Dynamic" ErrorMessage="Input Required" ValidationGroup="Detail"></asp:RequiredFieldValidator>
                                            <asp:RegularExpressionValidator ID="RegularExpressionValidator_Text" runat="server"
                                                ControlToValidate="txtBoxText" Display="Dynamic" ErrorMessage="Max 50 Chars"
                                                ValidationExpression=".{1,50}" ValidationGroup="Detail"></asp:RegularExpressionValidator>
                                        </EditItemTemplate>
                                        <InsertItemTemplate>
                                            <asp:TextBox ID="txtBoxText" runat="server" Text='<%# Bind("Title") %>' Columns="50"></asp:TextBox>
                                            <br />
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator_Text" runat="server" ControlToValidate="txtBoxText"
                                                Display="Dynamic" ErrorMessage="Input Required" ValidationGroup="Detail"></asp:RequiredFieldValidator>
                                            <asp:RegularExpressionValidator ID="RegularExpressionValidator_Text" runat="server"
                                                ControlToValidate="txtBoxText" Display="Dynamic" ErrorMessage="Max 50 Chars"
                                                ValidationExpression=".{1,50}" ValidationGroup="Detail"></asp:RegularExpressionValidator>
                                        </InsertItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label3" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Description" SortExpression="Description">
                                        <EditItemTemplate>
                                            <htmlEditor:HtmlEditor ID="txtBoxComment" runat="server" Text='<%# Bind("Description") %>' />
                                            <br />
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator_Comment" runat="server" ControlToValidate="txtBoxComment"
                                                Display="Dynamic" ErrorMessage="Input Required" ValidationGroup="Detail"></asp:RequiredFieldValidator>
                                        </EditItemTemplate>
                                        <InsertItemTemplate>
                                            <htmlEditor:HtmlEditor ID="txtBoxComment" runat="server" Text='<%# Bind("Description") %>' />
                                            <br />
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator_Comment" runat="server" ControlToValidate="txtBoxComment"
                                                Display="Dynamic" ErrorMessage="Input Required" ValidationGroup="Detail"></asp:RequiredFieldValidator>
                                        </InsertItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:CommandField ShowEditButton="True" ShowInsertButton="True" ValidationGroup="Detail" />
                                </Fields>
                            </asp:DetailsView>
                            <asp:SqlDataSource ID="Details" runat="server" ConnectionString="<%$ ConnectionStrings:AC_DBConnectionString %>"
                                SelectCommand="SELECT [ID], [ContentKey], [LanguageKey], [Title], [Description] FROM [AC_PageContent] WHERE ([ID] = @ID)"
                                UpdateCommand="UPDATE [AC_PageContent] SET [ContentKey] = @ContentKey, [LanguageKey] = @LanguageKey, [Title] = @Title, [Description] = @Description WHERE [ID] = @ID"
                                InsertCommand="INSERT INTO [AC_PageContent] ([ContentKey], [LanguageKey], [Title], [Description]) VALUES (@ContentKey, @LanguageKey, @Title, @Description)">
                                <SelectParameters>
                                    <asp:ControlParameter ControlID="gv_PageContent" Name="ID" PropertyName="SelectedValue"
                                        Type="String" />
                                </SelectParameters>
                                <UpdateParameters>
                                    <asp:ControlParameter Name="ContentKey" Type="String" ControlID="dv_PageContent$ddl_ContentKey"
                                        PropertyName="SelectedValue" />
                                    <asp:ControlParameter ControlID="dv_PageContent$ddl_Language" Name="LanguageKey"
                                        Type="String" PropertyName="SelectedValue" />
                                    <asp:Parameter Name="Title" Type="String" />
                                    <asp:Parameter Name="Description" Type="String" />
                                    <asp:Parameter Name="ID" Type="Int32" />
                                </UpdateParameters>
                                <InsertParameters>
                                    <asp:ControlParameter Name="ContentKey" Type="String" ControlID="dv_PageContent$ddl_ContentKey"
                                        PropertyName="SelectedValue" />
                                    <asp:ControlParameter ControlID="dv_PageContent$ddl_Language" Name="LanguageKey"
                                        Type="String" PropertyName="SelectedValue" />
                                    <asp:Parameter Name="Title" Type="String" />
                                    <asp:Parameter Name="Description" Type="String" />
                                </InsertParameters>
                            </asp:SqlDataSource>
                        </p>
                    </td>
                </tr>
            </table>
        </div>
        <asp:SqlDataSource ID="SqlDS_PageContent" runat="server" ConnectionString="<%$ ConnectionStrings:AC_DBConnectionString %>"
            SelectCommand="SELECT [ID], [ContentKey], [LanguageKey], [Title], [Description] FROM [AC_PageContent] ORDER BY [ID]"
            DeleteCommand="DELETE FROM [AC_PageContent] WHERE [ID] = @ID"></asp:SqlDataSource>
    </form>
</body>
</html>
